<?php
/**
 * Created by PhpStorm.
 * User: fengzi
 * Date: 2019/6/3
 * Time: 14:34
 */

namespace app\vehicle\logic;
use app\vehicle\model\Article;
use app\vehicle\model\ArticleCate;
use app\vehicle\model\Civilization;
use app\common\model\CivilizationCate;
use app\common\model\Study;
use app\common\model\StudyCate;
class articleLogic
{
    public function getCivilizationCate(){
        $list = CivilizationCate::where('status','eq',1)->where('pid','eq',0)->select();
        return $list;
    }
    public function getCivilizationList($data){
        $where[] = ['cate_id','eq',$data['cate_id']];
        $goods = Civilization::where($where)->order('create_time desc')->select();
        $cate_name = CivilizationCate::where('id','eq',$data['cate_id'])->value('name');
        return ['list'=>$goods,'cate_name'=>$cate_name];
    }
    public function getCivilizationInfo($data){
        Civilization::where('id','eq',$data['id'])->setInc('read_num',1);
        $info = Civilization::get($data['id']);
        //$info['content'] = str_replace('/ueditor/php/upload/image',config('database.img_url').'/ueditor/php/upload/image',$info['content']);
        //$info['content'] = htmlspecialchars_decode($info['content']);
        return $info;
    }
    public function getArticleCate(){
        $list = ArticleCate::where('status','eq',1)->select();
        return $list;
    }
    public function getArticleList($data){
        $where[] = ['status','eq',1];
        $page = 3;
        if($data['cate_id']){
            $page = 100;
            $where[] = ['cate_id','eq',$data['cate_id']];
        }
        $list = Article::where($where)->order('create_time desc')->page($data['page'],$page)->select();
        return $list;
    }
    public function getArticleInfo($data){
        Article::where('id','eq',$data['id'])->setInc('read_num',1);
        $info = Article::get($data['id']);
        $info['content'] = str_replace('/ueditor/php/upload/',config('database.img_url').'/ueditor/php/upload/',$info['content']);
        $info['content'] = htmlspecialchars_decode($info['content']);
        return $info;
    }

    public function getStudyCate(){
        $list = StudyCate::where('status','eq',1)->select();
        return $list;
    }
    public function getStudyList($data){
        $where[] = ['status','eq',1];
        $data['cate_id'] && $where[] = ['cate_id','eq',$data['cate_id']];
        $list = Study::where($where)->order('create_time desc')->page($data['page'],100)->select();
        return $list;
    }
    public function getStudyInfo($data){
        Study::where('id','eq',$data['id'])->setInc('read_num',1);
        $info = Study::get($data['id']);
        $info['content'] = str_replace('/ueditor/php/upload/image',config('database.img_url').'/ueditor/php/upload/image',$info['content']);
        $info['content'] = htmlspecialchars_decode($info['content']);
        return $info;
    }
}